package org.jumiz.framework.mysql.support;

import org.jumiz.framework.base.reflect.BeanDefinition;
import org.jumiz.framework.base.support.SqlBuilder;

/**
 * 构建可执行sql
 * @author Jumiz
 */
public class SqlBuilderImpl implements SqlBuilder {
    @Override
    public SqlResult buildPrepareSql(BeanDefinition beanDefinition) {
        StringBuilder sqlBuilder = new StringBuilder();
        switch (beanDefinition.getOperateType()) {
            case SELECT:
//                sqlBuilder.append(OperateType.SELECT);
//                List<FieldInfo> fields = beanDefinition.getFields();
//                if (fields == null || fields.isEmpty()) {
//                    sqlBuilder.append(" * ");
//                } else {
//                    String collect = fields.stream().map(item -> item.getName()).collect(Collectors.joining(", "));
//                    sqlBuilder.append(" ").append(collect).append(" ");
//                }
//                sqlBuilder.append(OperateType.FROM).append(" ").append(beanDefinition.getTableName());
//                List<FieldInfo> whereList = beanDefinition.getWhereList();
//                if (whereList != null && whereList.size() > 0) {
//                    sqlBuilder.append(" ").append(OperateType.WHERE);
//                    boolean first = true;
//                    for (FieldInfo fieldInfo : whereList) {
//                        sqlBuilder.append(first ? "" : " " + fieldInfo.getOperateType()).append(" ").append(fieldInfo.getName()).append(" = ").append("?");
//                        first = false;
//                    }
//                }
                break;
        }
        SqlResult sqlResult = new SqlResult();
        sqlResult.setSql(sqlBuilder.toString());
//        sqlResult.setParams();
        return sqlResult;
    }

    @Override
    public <T> String getTableName(Class<T> entityClass) {
        return entityClass.getSimpleName();
    }
}
